package com.liangchen.astools

import android.content.Context
import android.os.Handler
import com.liangchen.astools.core.AsTimerThread
import com.liangchen.astools.core.AsTimerThread.TimerHandler
import com.liangchen.astools.core.AsWorkerThread
import com.liangchen.astools.info.AsInfoManager
import com.liangchen.astools.utils.AsAppContext

object AsManager {
    var applicationContext: Context? = null
        private set
    private var asInfoManager: AsInfoManager? = null
        private set
    private var mTimerThread: AsTimerThread? = null
    private var mWorkerThread: AsWorkerThread? = null
    var timerHandler: Handler? = null
        private set
    private var mWorkerHandler: Handler? = null

    @JvmStatic
    fun init(context: Context) {
        applicationContext = context
        asInfoManager = AsInfoManager(context)
        if (mTimerThread == null) {
            mTimerThread = AsTimerThread("as-timer")
            mTimerThread!!.start()
            timerHandler = TimerHandler(mTimerThread)
        }
        if (mWorkerThread == null) {
            mWorkerThread = AsWorkerThread("as-worker")
            mWorkerThread!!.start()
            mWorkerHandler = AsWorkerThread.WorkerHandler(mWorkerThread!!)
        }
        AsAppContext.init(context)
    }

    @JvmStatic
    fun getmWorkerHandler(): Handler? {
        return mWorkerHandler
    }

    fun getAsInfoManager(): AsInfoManager? {
        return asInfoManager
    }
}

